package 线程池.forkjoin;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/8/15 11:05
 * @description:
 * @version:
 */
public class ForkJoinPoolExample {
    public static void main(String[] args) {
        // 创建ForkJoinPool对象
        ForkJoinPool forkJoinPool = new ForkJoinPool();

        try {
            // 创建FibonacciTask
            FibonacciTask task = new FibonacciTask(10);

            // 提交任务到ForkJoinPool进行执行
            Future<Integer> resultFuture = forkJoinPool.submit(task);

            // 等待任务执行完毕并获取结果
            int result = resultFuture.get();

            System.out.println("Result: " + result);
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        } finally {
            // 关闭ForkJoinPool
            forkJoinPool.shutdown();
        }
    }
}
